class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def sortedArrayToBST(self, nums):
        """
        :type nums: List[int]
        :rtype: TreeNode
        """
        if len(nums) == 1:
            return TreeNode(nums[0], None, None)
        if len(nums) == 2:
            return TreeNode(nums[0], None, TreeNode(nums[1], None, None))
        if len(nums) == 3:
            return TreeNode(nums[1], TreeNode(nums[0], None, None), TreeNode(nums[2], None, None))
        if len(nums) > 3:
            mid_index = int(len(nums) / 2)
            return TreeNode(nums[mid_index], self.sortedArrayToBST(nums[:mid_index]), self.sortedArrayToBST(nums[mid_index + 1:]))

data = Solution()
nums = [-10, -3, 0, 5, 9]
data.sortedArrayToBST(nums)
